﻿using System; 
using System.Collections.Generic; 
using System.ComponentModel; 

namespace DataAccess{
[Serializable]
[GenWiseAttribute(IsDataSourceEntity = true) ]
public class friend : INotifyPropertyChanged
 {


#region --- Class Fields / Objects  ---

[NonSerialized]
protected PropertyChangedEventHandler _propertyChanged;
private System.Int32 _inviting_user_id;
private System.Int32 _invited_user_id;
private System.String _status;
private user _user;
private user _user1;

#endregion


#region --- Class Properties ---

public virtual System.Int32 inviting_user_id 
{
get
{
return _inviting_user_id;
}
set 
{
if ( _inviting_user_id != value) 
{
_inviting_user_id = value ;
OnPropertyChanged("inviting_user_id");
}
}
}

public virtual System.Int32 invited_user_id 
{
get
{
return _invited_user_id;
}
set 
{
if ( _invited_user_id != value) 
{
_invited_user_id = value ;
OnPropertyChanged("invited_user_id");
}
}
}

public virtual System.String status 
{
get
{
return _status;
}
set 
{
if ( _status != value) 
{
_status = value ;
OnPropertyChanged("status");
}
}
}

/// <summary>
/// Generated from Relation FK_Friend_User
/// </summary>
[GenWiseAttribute(RelationID = "5dfc23d9-aa81-4877-a0f8-ef1c22d7b946") ]
public virtual user user 
{
get
{
if ( _user == null ) 
{
if (  _inviting_user_id.Equals(0)  || _inviting_user_id.Equals(System.Int32.MinValue) ) 
{
if ( _user != null && ( _user.id.Equals(System.Int32.MinValue) ) )
{
  _user = null;
}
}
else
{
_user = (new userFactory()).Get(_inviting_user_id);
}
}

return _user;
}
set 
{
if ( _user != value) 
{
if ( value==null ) _inviting_user_id = System.Int32.MinValue; else _inviting_user_id = (System.Int32)value.id; 
_user = value ;
}
}
}

/// <summary>
/// Generated from Relation FK_Friend_User1
/// </summary>
[GenWiseAttribute(RelationID = "a329f9c9-1664-466d-920e-e3dfbd4953fd") ]
public virtual user user1 
{
get
{
if ( _user1 == null ) 
{
if (  _invited_user_id.Equals(0)  || _invited_user_id.Equals(System.Int32.MinValue) ) 
{
if ( _user1 != null && ( _user1.id.Equals(System.Int32.MinValue) ) )
{
  _user1 = null;
}
}
else
{
_user1 = (new userFactory()).Get(_invited_user_id);
}
}

return _user1;
}
set 
{
if ( _user1 != value) 
{
if ( value==null ) _invited_user_id = System.Int32.MinValue; else _invited_user_id = (System.Int32)value.id; 
_user1 = value ;
}
}
}

/// <summary>
/// Property that simulates a unique PK by concatenating all the Pk properties
/// </summary>
public virtual System.String VirtualPk 
{
get
{
string _retValue = string.Empty;

_retValue += inviting_user_id.ToString();

_retValue += "^";
_retValue += invited_user_id.ToString();

return _retValue;

}
}

/// <summary>
/// Is this object Valid? 
/// </summary>
/// <remarks>
/// This is achieved by counting how many errors are returned from the Validate() method. If no errors are found then it's valid.
/// </remarks>
[Bindable(false)]
public virtual System.Boolean IsValid 
{
get
{
List<Error> _errors = this.Validate(); if ( _errors.Count > 0 ) return false; else return true;
}
}


#endregion


#region --- Class Methods --- 

/// <summary>
/// Raises PropertyChanged event.
/// </summary>
protected virtual void OnPropertyChanged(System.String ppropertyChanged)
{
if (_propertyChanged != null) _propertyChanged( this , new PropertyChangedEventArgs(ppropertyChanged));

}

/// <summary>
/// Create a new friend object. 
/// </summary>
public  friend()
{
}

/// <summary>
/// Create a new instance/object
/// </summary>
public  friend(System.Int32 pinviting_user_id , System.Int32 pinvited_user_id)
{
_inviting_user_id = pinviting_user_id ;
_invited_user_id = pinvited_user_id ;

}

public override int GetHashCode()
{
string _hash = String.Empty; 
_hash += inviting_user_id.ToString();
_hash += invited_user_id.ToString();
return _hash.GetHashCode(); 

}

public override bool Equals(object pobject)
{
friend _newfriend = (pobject as friend); 
if (_newfriend == null ) return false; 
if (_newfriend.GetHashCode() == this.GetHashCode() ) return true; 
return false; 

}

/// <summary>
/// Validates the object returning a list of errors if the validation fails.
/// </summary>
/// <remarks>
/// You can use the provided User CodeBlocks to add your own validations.
/// </remarks>
///<returns>Returns the List of Errors found during the Validation. If no errors are found null is returned.<returns>
public virtual List<Error> Validate()
{
List<Error> _errors = new List<Error>();
Error _error;
// Call Validator IsRequired for Column : status(Type:Required Field Validator)
_error = this.ValidatestatusIsRequired() ;
 if ( _error != null ) { _errors.Add(_error); }

// Primary Key Validation (Template Option)
if (  inviting_user_id.Equals(0)  ) 
{
   _errors.Add( new Error( "The PK Column (inviting_user_id) can not be null!. " ) );
}
if (  invited_user_id.Equals(0)  ) 
{
   _errors.Add( new Error( "The PK Column (invited_user_id) can not be null!. " ) );
}

return _errors;
}

/// <summary>
/// Validation Method
/// </summary>
/// <remarks>
/// This method was automatically generated based on the DataBase Repository Validations for the Column : status
/// </remarks>
public virtual Error ValidatestatusIsRequired()
{
if ( String.IsNullOrEmpty(status) ) 
{
 Error _error = new Error();
 _error.ErrorMessage = "status is required and therefore must have a value." ;
 return _error;
}
 return null;
}


#endregion


#region --- Class Events  ---

public event PropertyChangedEventHandler PropertyChanged 
{
   add {
_propertyChanged+= value;
   }
   remove {
_propertyChanged-= value;
   }
}


#endregion
}
}

